package com.game.cards;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.game.play.ActionQueue;
import com.game.play.Game;
import com.game.play.Player;

public class Hand {
	
	private List<BaseCard> cards;
	private Game game;
	private Player owner;
	private int limit;
	
	public Hand(Game game, Player owner)
	{
		this.cards = new ArrayList<BaseCard>();
		this.game = game;
		this.owner = owner;
		this.limit = 7;
	
	}
	
	public Game getGame() {
		return game;
	}

	public Player getOwner() {
		return owner;
	}

	public void setOwner(Player owner) {
		this.owner = owner;
	}
	public int handSize()
	{
		return cards.size();
	}
	public void shuffle()
	{
		Collections.shuffle(this.cards);
	}
	public void addCard(BaseCard c)
	{
		this.cards.add(c);
	}
	public void addCards(List<BaseCard> c)
	{
		this.cards.addAll(c);
	}
	public void draw(int amount,ActionQueue aq)
	{
		//if((this.getCards().size() + amount) <= this.limit) 
			this.addCards(this.owner.getCurrentDeck().draw(amount, aq));
	}
	public List<BaseCard> getCards()
	{
		return this.cards;
	}
	
	public List<BaseCard> getMonsterCards()
	{
		List<BaseCard> temp = new ArrayList<BaseCard>();
		for (BaseCard c : this.cards)
		{
			if (c instanceof MonsterCard)
			{
				temp.add(c);
			}
		}
		return temp;
	}
	public List<BaseCard> getSpellCards()
	{
		List<BaseCard> temp = new ArrayList<BaseCard>();
		for (BaseCard c : this.cards)
		{
			if (c instanceof SpellCard)
			{
				temp.add(c);
			}
		}
		return temp;
	}
	public List<BaseCard> getTrapCards()
	{
		List<BaseCard> temp = new ArrayList<BaseCard>();
		for (BaseCard c : this.cards)
		{
			if (c instanceof TrapCard)
			{
				temp.add(c);
			}
		}
		return temp;
	}
	public boolean removeCardById(int id)
	{
		for (BaseCard c : this.cards)
		{
			if (c.getId() == id) {
				this.cards.remove(c);
				return true;
			}
		}
		return false;
	}

}
